package com.share.shrimpcolo;

import java.io.File;
import java.util.Scanner;

/**
 * （15分）编写一个程序，当用户输入一个目录时，该程序能列出该目录下的所有子目录和文件，并且有层级区分。
 * @author Johnny Tam
 *
 */
public class LooperDocument {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.println("请输入文件目录");
		
		//E:\Coursera-Java\Eclipse\workspace\ThirdTest
		String path = input.next();
		System.out.println(path);
		File file = new File(path);
		
		if(!file.exists()) {
			System.out.println("该文件目录不存在");
		}else{
			loopDocument(file, 0);
		}
	}
	
	public static void loopDocument(File file, int level) {
		
		String preStr = "";
		for (int i = 0; i < level; i++) {
			preStr += "    ";
		}
		File[] childs = file.listFiles();
		if (childs != null) {
			for (int i = 0; i < childs.length; i++) {
				
				System.out.println(preStr + childs[i].getName());
				
				if (childs[i].isDirectory()) {
					loopDocument(childs[i], level + 1);
				}
			}
		}//end if
		
	}

}
